//
//  LOLMineViewController.m
//  LOLXXbox
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLMineViewController.h"
#import <UIImageView+WebCache.h>
#import "LOLwhatViewController.h"
#import "LOLFavorViewController.h"
#import "LiveVideoViewController.h"
@interface LOLMineViewController ()<UITableViewDataSource,UITableViewDelegate>


@property (nonatomic, retain)UITableView *tableView;

@end

@implementation LOLMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"管理";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.tableView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView {
    if (!_tableView) {
        self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"我的收藏";
        
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"直播间";
    }else if (indexPath.row == 2){
        cell.textLabel.text = @"常见问题";
    }else if (indexPath.row == 3) {
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        float sizeMB = size / 1024.0 / 1024.0;
        cell.textLabel.text = [NSString stringWithFormat:@"清除缓存                                                %0.2fMB", sizeMB];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (indexPath.row == 3) {
        //清除缓存
        [[SDImageCache sharedImageCache] clearDisk];
        //获取缓存大小
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        float sizeMB = size / 1024.0 / 1024.0;
        UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"已成功清除缓存" message:@"清空缓存之后，图片资源，收藏都已清空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        cell.textLabel.text = [NSString stringWithFormat:@"清除缓存                                                %0.2fMB", sizeMB];
        [alter show];

    }else if (indexPath.row == 2) {
        LOLwhatViewController *webView = [[LOLwhatViewController alloc] init];
        webView.url = @"http://lol.duowan.com/1310/247055103960.html";
        [self.navigationController pushViewController:webView animated:YES];
    }else if (indexPath.row == 0){
        LOLFavorViewController *mine = [[LOLFavorViewController alloc] init];
        [self.navigationController pushViewController:mine animated:YES];
    
    }else if (indexPath.row == 1){
        LiveVideoViewController *liveVideo = [[LiveVideoViewController alloc] init];
        [self.navigationController pushViewController:liveVideo animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        return  60;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
